package com.sc.nft.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.sc.nft.admin.request.*;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.EcologyHatchDaoIncomeConf;
import com.sc.nft.entity.vo.AdminShareProfitCollectPointsVO;
import com.sc.nft.entity.vo.ecology.AdminDaoEcologyIncomePageVO;
import com.sc.nft.entity.vo.ecology.AdminShareProfitCollectDetailsVO;
import com.sc.nft.entity.vo.ecology.AdminShareProfitCollectVO;
import com.sc.nft.service.AdminEcologyDaoIncomeConfService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/dao/ecology/income")
@Api(tags = "后台生态铸造配置管理")
public class AdminDaoEcologyIncomeConfController {


    private final AdminEcologyDaoIncomeConfService adminEcologyDaoIncomeConfService;


    @PostMapping(value = "/page", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "DAO收益列表", notes = "DAO收益列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminDaoEcologyIncomePageVO> page(@Valid @RequestBody AdminDaoEcologyIncomePageRequest request) {
        return PageResult.success(adminEcologyDaoIncomeConfService.page(request.getDaoName(), request.getDividendIncomeName(), request.getStatus(), request.getPageNo(), request.getPageSize()));
    }


    @PostMapping(value = "/addConf", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "新增DAO收益", notes = "新增DAO收益", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result addConf(@Valid @RequestBody AddConfRequest request) {
        EcologyHatchDaoIncomeConf ecologyHatchDaoIncomeConf = BeanUtil.copyProperties(request, EcologyHatchDaoIncomeConf.class);
        adminEcologyDaoIncomeConfService.addConf(ecologyHatchDaoIncomeConf);
        return Result.success();
    }

    @PostMapping(value = "/deleteConf", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除DAO收益", notes = "删除DAO收益", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result deleteConf(@Valid @RequestBody IdRequest request) {
        adminEcologyDaoIncomeConfService.deleteConf(request.getId());
        return Result.success();
    }

    @PostMapping(value = "/updateStatus", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改上/下架", notes = "修改上/下架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateStatus(@Valid @RequestBody StatusRequest request) {
        adminEcologyDaoIncomeConfService.updateStatus(request.getId(), request.getStatus());
        return Result.success();
    }



    @PostMapping(value = "/updateConf", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改DAO收益", notes = "新增DAO收益", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateConf(@Valid @RequestBody UpdateDaoEecologyIncomeRequest request) {
        EcologyHatchDaoIncomeConf ecologyHatchDaoIncomeConf = BeanUtil.copyProperties(request, EcologyHatchDaoIncomeConf.class);
        adminEcologyDaoIncomeConfService.updateConf(ecologyHatchDaoIncomeConf);
        return Result.success();
    }
    @PostMapping(value = "/shareProfitCollect", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "分润汇总数据", notes = "分润汇总数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<AdminShareProfitCollectVO> shareProfitCollect(@Valid @RequestBody IdRequest request) {
        return Result.success(adminEcologyDaoIncomeConfService.shareProfitCollect(request.getId()));
    }

    @PostMapping(value = "/shareProfitCollectDetails", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "分润汇总详情数据", notes = "分润汇总详情数据", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminShareProfitCollectDetailsVO> shareProfitCollectDetails(@Valid @RequestBody ShareProfitCollectDetailsRequest request) {
        return PageResult.success(adminEcologyDaoIncomeConfService.shareProfitCollectDetails(request.getCollectionId(),request.getUserTel(),request.getStartTime(),request.getEndTime(),request.getPageNo(),request.getPageSize()));
    }

    @PostMapping(value = "/shareProfitCollectPoints", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "分润汇总数据-积分", notes = "分润汇总数据-积分", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<AdminShareProfitCollectPointsVO> shareProfitCollectPoints(@Valid @RequestBody IdRequest request) {
        return Result.success(adminEcologyDaoIncomeConfService.shareProfitCollectPoints(request.getId()));
    }
}
